home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / src / load.shl.c < prev    next >
C/C++ Source or Header  |  1992-11-03  |  2KB  |  73 lines

  1. #include <dl.h>
  2. #include <string.h>
  3.  
  4. extern int errno;
  5.  
  6. static void Load_Them (names) Object names; {
  7.     char *fn;
  8.     shl_t handle;
  9.     SYM *sp;
  10.     Declare_C_Strings;
  11.  
  12.     for ( ; !Nullp (names); names = Cdr (names)) {
  13.     Make_C_String (Car (names), fn);
  14.     if (Verbose)
  15.         printf ("shl_load(%s)\n", fn);
  16.     if ((handle = shl_load (fn, BIND_IMMEDIATE|BIND_VERBOSE, 0L)) == 0) {
  17.         Saved_Errno = errno;
  18.         Primitive_Error ("shl_load of ~s failed: ~E", Car (names));
  19.     }
  20.     if (The_Symbols)
  21.         Free_Symbols (The_Symbols);
  22.     The_Symbols = Open_File_And_Snarf_Symbols (fn);
  23.     for (sp = The_Symbols->first; sp; sp = sp->next)
  24.         if (shl_findsym (&handle, sp->name, TYPE_UNDEFINED, &sp->value)) {
  25.         Saved_Errno = errno;
  26.         Primitive_Error ("~s: shl_findsym on ~s failed: ~E",
  27.             Car (names),
  28.             Make_String (sp->name, strlen (sp->name)));
  29.     }
  30.     if (!Call_Initializers (The_Symbols, 0))
  31.         Primitive_Error ("no initializers in ~s", Car (names));
  32.     }
  33.     Dispose_C_Strings;
  34. }
  35.  
  36. Load_Object (names) Object names; {
  37.     Object port, tail, fullnames, str;
  38.     char *p, *libs = "";
  39.     static struct lib_loaded {
  40.     struct lib_loaded *next;
  41.     char *lib_name;
  42.     } *libs_loaded, *lp;
  43.     
  44.     GC_Node3;
  45.     Declare_C_Strings;
  46.  
  47.     port = tail = fullnames = Null;
  48.     GC_Link3 (port, tail, fullnames);
  49.     for (tail = names; !Nullp (tail); tail = Cdr (tail)) {
  50.     port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
  51.     fullnames = Cons (PORT(port)->name, fullnames);
  52.     (void)P_Close_Input_Port (port);
  53.     }
  54.     tail = Var_Get (V_Load_Libraries);
  55.     if (TYPE(tail) == T_String)
  56.     Make_C_String (tail, libs);
  57.     for (tail = Null; (p = strtok (libs, " \t")) != 0; libs = 0) {
  58.     for (lp = libs_loaded; lp; lp = lp->next)
  59.         if (strcmp (lp->lib_name, p) == 0) break;
  60.     if (lp) continue;
  61.     lp = (struct lib_loaded *)Safe_Malloc (sizeof (*lp));
  62.     lp->lib_name = strdup (p);
  63.     lp->next = libs_loaded;
  64.     libs_loaded = lp;
  65.     str = Make_String (p, strlen (p));
  66.     tail = Cons (str, tail);
  67.     }
  68.     Load_Them (tail);
  69.     Load_Them (fullnames);
  70.     GC_Unlink;
  71.     Dispose_C_Strings;
  72. }
  73.